/*
	This file is part of PropExtractor.

	AliceDecrypt is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	AliceDecrypt is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with PropExtractor. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _PEALICESOFTMODEL_H_
#define _PEALICESOFTMODEL_H_

#include "PEIncludes.h"

#include "PEFile.h"

namespace pe
{

	struct AliceModelZippedHeader
	{
		byte header[3];
		byte padding[5];
		dword datasize;
		dword unknown1;
	};

	struct AliceModelData
	{
		PEFile* handle;
		byte* data;
		unsigned int datasize;
	};

	struct AliceModelHeader
	{
		byte header[3];
		byte padding;
		dword unknown1;
		dword mesh_count;
	};

	struct AliceVertexData1
	{
		byte data[14];
	};

	struct AliceVertexData2
	{
		float vx, vy, vz;
		word unknown1;
		word unknown2;
	};

	struct AliceVertexData3
	{
		byte data[40];
	};

	struct AliceUVData1
	{
		float x, y;
	};

	struct AliceNormalData1
	{
		byte data[76];
	};

	struct AliceFaceData
	{
		dword vertex_index[3];
		dword uv_index[3];
		dword unknown1[3];
		float unknown2[10];
	};

	struct AliceMaterial
	{
		char* name;
		char* texture;
		unsigned int index;
	};

	struct AliceMesh
	{
		char* name;
		AliceMaterial* material;

		AliceVertexData1* vertex_data1;
		AliceVertexData2* vertex_data2;
		unsigned int vertex_total;

		AliceUVData1* uv_data1;
		unsigned int uv_total;

		AliceFaceData* face_data;
		unsigned int face_total;
	};

	struct AliceModel
	{
		AliceModelHeader* header;

		AliceMaterial* material;
		unsigned int material_total;

		AliceMesh* mesh;
		unsigned int mesh_total;
	};

	int AliceZippedModelReadHeader(AliceModelZippedHeader* a_Target, PEFile* a_File);
	int AliceZippedModelDecompress(AliceModelData* a_Target, AliceModelZippedHeader* a_Header, PEFile* a_File);
	int AliceModelSaveToFile(AliceModelData* a_Data, const char* a_FilePath, const char* a_Pattern = NULL);
	int AliceModelDecrypt(AliceModel* a_Target, AliceModelData* a_Data);
	int AliceSaveModelToObj(AliceModel* a_Model, const char* a_FilePath);

}; // namespace pe

#endif